﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2可以删除
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime? expiredDate = null;
            string s= expiredDate.ToString();
            string aa = s.ToString("yyyy-MM-dd");
        }
        /// <summary>
        /// 可空类型转换
        /// </summary>
        /// <typeparam name="T">转换的可空类型</typeparam>
        /// <param name="s">字符串</param>
        /// <returns>T</returns>
        public static T ToNullable<T>(string s)
        {
            if (string.IsNullOrEmpty(s))
            {
                return default(T);
            }
            else
            {
                try
                {
                    return (T)Convert.ChangeType(s, typeof(T).GetGenericArguments()[0]);
                }
                catch
                {
                    return default(T);
                }
            }
        }
    }
}
